package ltd.ninefish.framework.systemapi.factory;

import ltd.ninefish.framework.core.result.Result;
import ltd.ninefish.framework.systemapi.dto.LoginUserDto;
import ltd.ninefish.framework.systemapi.dto.SysUserDto;
import ltd.ninefish.framework.systemapi.service.RemoteUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @author zhaoxiubin
 * create-time 2024-01-16 8:43
 * description RemoteUserFallbackFactory
 **/
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);

    @Override
    public RemoteUserService create(Throwable cause) {
        log.error("用户服务调用失败:{}", cause.getMessage());
        return new RemoteUserService()
        {
            @Override
            public Result<LoginUserDto> getUserInfo(String username, String source)
            {
                return Result.fail("获取用户失败:" + cause.getMessage());
            }

            @Override
            public Result<LoginUserDto> getUserInfoByWx(String username, String source)
            {
                return Result.fail("获取用户失败:" + cause.getMessage());
            }

            @Override
            public Result<LoginUserDto> getUserInfoByTel(String username, String source)
            {
                return Result.fail("获取用户失败:" + cause.getMessage());
            }

            @Override
            public Result<Boolean> registerUserInfo(SysUserDto sysUser, String source)
            {
                return Result.fail("注册用户失败:" + cause.getMessage());
            }
        };
    }
}
